package com.smq.chatserver.controller;

import com.smq.chatserver.mqtt.MqttGateway;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "MQTT模块")
@RestController
@RequestMapping("/mqtt")
public class MqttController {

    @Autowired
    @Qualifier("mqttGateway")
    private MqttGateway mqttGateWay;

    @ApiOperation(value = "发送消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "topic", value = "好友id"),
            @ApiImplicitParam(name = "message", value = "信息")
    })
    @PostMapping("/sendMessage")
    public String sendMessage(String topic, String message) {
        // 发送消息到指定topic
        mqttGateWay.sendToMqtt(topic, 1, message);
        return "send topic: " + topic + ", message : " + message;
    }

}
